package com.cjz.demo6;

import java.util.Arrays;
import java.util.List;

import rx.Observable;
import rx.schedulers.Schedulers;

/**
 * RxJava的Observable Operators
 */

public class Test {

    public static void main(String[] args) throws InterruptedException {


        //testRxJava();
        testRxJava2();


        Thread.sleep(10_000);
    }

    private static void testRxJava() {

        Observable
                .just("abc", "def", "ghi")
                .take(1)
                .subscribeOn(Schedulers.io())
                .subscribe(System.out::println);
    }


    private static void testRxJava2() {

        String[] stringArray = {"abc", "def", "ghi"};
        List<String> stringList = Arrays.asList(stringArray);

        Observable
                .from(stringList)
                .filter(s -> s.startsWith("d"))
                .map(s -> s + "_ha")
                .takeLast(1)
                .repeat(3)
                .onBackpressureBuffer()
                .subscribeOn(Schedulers.computation())
                .observeOn(Schedulers.newThread())
                .subscribe(System.out::println);

    }

}
